<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./code/chapter/16_game.js"></script>
    <script src="./code/levels.js"></script>

    <link rel="stylesheet" href="./css/game.css">
</head>

<body>
    <script>
        function runLevel(level, Display) {
            let display = new Display(document.body, level);
            let state = State.start(level);
            let ending = 1;
            return new Promise(resolve => {
                runAnimation(time => {
                    state = state.update(time, arrowKeys);
                    display.setState(state);
                    if (state.status == "playing") {
                        return true;
                    } else if (ending > 0) {
                        ending -= time;
                        return true;
                    } else {
                        display.clear();
                        resolve(state.status);
                        return false;
                    }
                });
            });
        }
        runGame(GAME_LEVELS, DOMDisplay);
    </script>
</body>

</html>